package demo3;

import static java.lang.Thread.sleep;

public class TwoThread {
    public static void main(String[] args) {
        SimpleThread simpleThread1 =new SimpleThread("线程1");
        SimpleThread simpleThread2 =new SimpleThread("线程2");
        Thread t1 = new Thread(simpleThread1);
        Thread t2 = new Thread(simpleThread2);
        t1.start();
        t2.start();

    }
}

class SimpleThread implements Runnable {
    String str;

    public SimpleThread(String str) {
        this.str = str;
    }

    @Override
    public void run() {
        for (int i = 0; i < 4; i++) {
            System.out.println(i + " " + this.getStr());
            try {
                sleep((int) (Math.random()*1000));
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("DONE!" + getStr());
    }

    public String getStr() {
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }
}